package com.betterjr.modules.risk.loan.entity;

import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

import com.betterjr.common.annotation.MetaData;
import com.betterjr.common.entity.BetterjrEntity;
import com.betterjr.common.selectkey.SerialGenerator;

@Access(AccessType.FIELD)
@Entity
@Table(name = "t_scf_loan_cust_core_relation")
public class LoanCustCodeRelation implements BetterjrEntity {

    /** 
     * @Fields serialVersionUID : 
     */
    private static final long serialVersionUID = -1050270269076563591L;

    /**
     * 流水号
     */
    @Id
    @Column(name = "ID", columnDefinition = "INTEGER")
    @MetaData(value = "流水号", comments = "流水号")
    private Long id;

    /**
     * 供应商编号
     */
    @Column(name = "L_CUSTNO", columnDefinition = "INTEGER")
    @MetaData(value = "供应商编号", comments = "供应商编号")
    private Long custNo;

    /**
     * 核心企业编号
     */
    @Column(name = "L_CORENO", columnDefinition = "INTEGER")
    @MetaData(value = "核心企业编号", comments = "核心企业编号")
    private Long coreNo;

    /**
     * 供应商企业代码
     */
    @Column(name = "C_CUSTCODE", columnDefinition = "VARCHAR")
    @MetaData(value = "供应商企业代码", comments = "供应商企业代码")
    private String custCode;

    /**
     * 优先级。匹配次数
     */
    @Column(name = "L_PRIORITY_LEVEN", columnDefinition = "INTEGER")
    @MetaData(value = "优先级。匹配次数", comments = "优先级。匹配次数")
    private int priorityLeven;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getCustNo() {
        return custNo;
    }

    public void setCustNo(Long custNo) {
        this.custNo = custNo;
    }

    public Long getCoreNo() {
        return coreNo;
    }

    public void setCoreNo(Long coreNo) {
        this.coreNo = coreNo;
    }

    public String getCustCode() {
        return custCode;
    }

    public void setCustCode(String custCode) {
        this.custCode = custCode;
    }

    public int getPriorityLeven() {
        return priorityLeven;
    }

    public void setPriorityLeven(int priorityLeven) {
        this.priorityLeven = priorityLeven;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((coreNo == null) ? 0 : coreNo.hashCode());
        result = prime * result + ((custCode == null) ? 0 : custCode.hashCode());
        result = prime * result + ((custNo == null) ? 0 : custNo.hashCode());
        result = prime * result + ((id == null) ? 0 : id.hashCode());
        result = prime * result + priorityLeven;
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (!(obj instanceof LoanCustCodeRelation)) {
            return false;
        }
        LoanCustCodeRelation other = (LoanCustCodeRelation) obj;
        if (coreNo == null) {
            if (other.coreNo != null) {
                return false;
            }
        } else if (!coreNo.equals(other.coreNo)) {
            return false;
        }
        if (custCode == null) {
            if (other.custCode != null) {
                return false;
            }
        } else if (!custCode.equals(other.custCode)) {
            return false;
        }
        if (custNo == null) {
            if (other.custNo != null) {
                return false;
            }
        } else if (!custNo.equals(other.custNo)) {
            return false;
        }
        if (id == null) {
            if (other.id != null) {
                return false;
            }
        } else if (!id.equals(other.id)) {
            return false;
        }
        if (priorityLeven != other.priorityLeven) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "LoanCustCodeRelation [id=" + id + ", custNo=" + custNo + ", coreNo=" + coreNo + ", custCode=" + custCode
                + ", priorityLeven=" + priorityLeven + "]";
    }

    public void saveAddInitValue(String anCustCode, Long anCoreNo, Long CustNo) {
        this.setCoreNo(anCoreNo);
        this.setCustCode(anCustCode);
        this.setCustNo(CustNo);

        this.setPriorityLeven(0);
        this.setId(SerialGenerator.getLongValue("LoanCustCodeRelation.id"));
    }

}
